package com.zx.demo.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @description: 分页对象
 * @author: zhou  xun
 * @create: 2022-09-27 09:06
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageInfo {
    /**
     * 页数
     */
    private Integer pageNum;
    /**
     * 页面大小
     */
    private Integer pageSize;


    public Integer getPageSize() {
        if (this.pageSize == null || this.pageSize == 0) {
            this.pageSize = 20;
        }
        return this.pageSize;
    }

    /**
     * <p>分页计算公式:<br>
     * sql语句：select * from 表名 limit start,pageSize;<br>
     * start:就是当前页的起始索引,pageSize就是每页的条数.<br>
     * currentPage:就是当前页.<br>
     * 公式:start=(currentPage-1)*pageSize
     * </p>
     *
     * @return
     */
    public Integer getPageNum() {
        if (this.pageNum == null) {
            this.pageNum = 0;
        }
        return this.pageNum * this.getPageSize();
    }


}

